package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BasePartnerBank;
import com.sumi.erp.service.IBasePartnerBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合作伙伴银行Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/erp/bank")
public class BasePartnerBankController extends BaseController
{
    @Autowired
    private IBasePartnerBankService basePartnerBankService;

    /**
     * 查询合作伙伴银行列表
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasePartnerBank basePartnerBank)
    {
        startPage();
        List<BasePartnerBank> list = basePartnerBankService.selectBasePartnerBankList(basePartnerBank);
        return getDataTable(list);
    }

    /**
     * 导出合作伙伴银行列表
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:export')")
    @Log(title = "合作伙伴银行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasePartnerBank basePartnerBank)
    {
        List<BasePartnerBank> list = basePartnerBankService.selectBasePartnerBankList(basePartnerBank);
        ExcelUtil<BasePartnerBank> util = new ExcelUtil<BasePartnerBank>(BasePartnerBank.class);
        util.exportExcel(response, list, "合作伙伴银行数据");
    }

    /**
     * 获取合作伙伴银行详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basePartnerBankService.selectBasePartnerBankById(id));
    }

    /**
     * 新增合作伙伴银行
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:add')")
    @Log(title = "合作伙伴银行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePartnerBank basePartnerBank)
    {
        return toAjax(basePartnerBankService.insertBasePartnerBank(basePartnerBank));
    }

    /**
     * 修改合作伙伴银行
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:edit')")
    @Log(title = "合作伙伴银行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePartnerBank basePartnerBank)
    {
        return toAjax(basePartnerBankService.updateBasePartnerBank(basePartnerBank));
    }

    /**
     * 删除合作伙伴银行
     */
    @PreAuthorize("@ss.hasPermi('erp:bank:remove')")
    @Log(title = "合作伙伴银行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basePartnerBankService.deleteBasePartnerBankByIds(ids));
    }
}
